package com.ruibang.glass.produce.component.job;

import com.ruibang.glass.produce.entity.Hot2StatisticalReport;
import com.ruibang.glass.produce.service.Hot2StatisticalReportService;
import com.teaming.cloud.framework2.elastic.job3.annotation.ElasticJobScheduler;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneOffset;

/**
 * @Author: songJinKang
 * @CreateTime: 2024-05-27  14:33
 * @Description: TODO:热端2生产统计报表任务
 * @Version: 1.0
 */

@Slf4j
@ElasticJobScheduler(cron = "6 11 0/1 * * ?")
//@ElasticJobScheduler(cron = "0 * * * * ?")
@Component
public class Hot2StatisticalReportTask implements SimpleJob {


    @Autowired
    private Hot2StatisticalReportService hot2StatisticalReportService;

    @Override
    public void execute(ShardingContext shardingContext) {
        LocalDateTime end = LocalDateTime.now().minusHours(1);
        LocalDateTime start = end.minusHours(1);
        LocalDateTime endTime = LocalDateTime.of(end.getYear(), end.getMonthValue(), end.getDayOfMonth(), end.getHour(), 0, 0);
        LocalDateTime startTime = LocalDateTime.of(start.getYear(), start.getMonthValue(), start.getDayOfMonth(), start.getHour(), 0, 0);
        long endTs = endTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        long startTs = startTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        Hot2StatisticalReport hot2StatisticalReport = hot2StatisticalReportService.executeHourTask(startTs, endTs);
        hot2StatisticalReport.setCollectTime(startTime);
        hot2StatisticalReportService.save(hot2StatisticalReport);
    }


}
